/*
 * MineralPhase.cpp
 *
 *  Created on: 24 May 2011
 *      Author: allan
 */

#include "MineralPhase.h"

// C++ includes
#include <numeric>

MineralPhase::MineralPhase()
{}

MineralPhase::MineralPhase(const StringVector& species)
{
	SetSpecies(species);
}

MineralPhase::~MineralPhase()
{}

void MineralPhase::SetSpecies(const StringVector& species)
{
	Phase::SetSpecies(species);
}

const String MineralPhase::GetName() const
{
	return "Mineral";
}

const DoubleVector MineralPhase::ActivityCoefficients(double T, double P, const DoubleVector& n) const
{
	DoubleVector lambda(n.size(), 1.0);
	
	return lambda;
}

const DoubleVector MineralPhase::Activities(double T, double P, const DoubleVector& n) const
{
	// The activities of the minerals
	DoubleVector a(ActivityCoefficients(T, P, n));
	
	// The total number of moles in the mineral phase
	const double nT = std::accumulate(n.begin(), n.end(), 0.0);
	
	// Loop over all the minerals and multiply a by the corresponding molar fraction of the mineral
	for(unsigned i = 0; i < n.size(); ++i)
		a[i] *= n[i]/nT;
	
	return a;
}
